from langgraph.graph import StateGraph
from typing_extensions import TypedDict,Annotated,List
from langchain_openai import ChatOpenAI
import operator


class State(TypedDict):  # 状态定义
    message:Annotated[List[str],operator.add]
bulier = StateGraph(State) #state类型为dict
def add_node(state):
   msg = state['message'][-1]['x']+1
   return {'message':[{'x':msg}]}
def sub_node(state):
  return {'message':[{'y':state['message'][-1]['x']-2}]}
  
bulier.add_node('add_node',add_node)
bulier.add_node('sub_node',sub_node)
bulier.set_entry_point('add_node')  
bulier.set_finish_point('sub_node')
bulier.add_edge('add_node','sub_node')
graph = bulier.compile()
m={'message':[{'x':10}]}
print(graph.invoke(m))

